//
//  CPTLayer+MoveAnimation.m
//  Wallets Manager
//
//  Created by Nguyen Chi Cong on 10/23/12.
//  Copyright (c) 2012 BKHN. All rights reserved.
//

#import "CPTLayer+MoveAnimation.h"

@implementation CPTLayer(MoveAnimation)

-(void)moveLayer:(CALayer*)layer to:(CGPoint)point
{
    // Prepare the animation from the current position to the new position
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
    animation.fromValue = [layer valueForKey:@"position"];
    
    // NSValue/+valueWithPoint:(NSPoint)point is available on Mac OS X
    // NSValue/+valueWithCGPoint:(CGPoint)point is available on iOS
    // comment/uncomment the corresponding lines depending on which platform you're targeting
    
    // Mac OS X
    //animation.toValue = [NSValue valueWithPointer:NSPointFromCGPoint(point)];
    // iOS
    animation.toValue = [NSValue valueWithCGPoint:point];
    
    // Update the layer's position so that the layer doesn't snap back when the animation completes.
    layer.position = point;
    
    // Add the animation, overriding the implicit animation.
    [layer addAnimation:animation forKey:@"position"];
}

@end
